<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>dom操作初探</title>
</head>
<body>

    <div></div>
    <script>
        var div = document.getElementsByTagName("div")[0];
        div.style.height = "100px";
        div.style.width = "100px";
        div.style.backgroundColor = "yellow";
        var count = 0;
        div.onclick = function () {
            count++;
            if(count % 2 == 1){
                this.style.backgroundColor = "red";
            }else {
                this.style.backgroundColor = "yellow";
            }
        }
    </script>
</body>
</html>
